package com.css.zfzx.sjcj.modules.hddcActiveFaultPositionerror.repository;

import com.css.zfzx.sjcj.modules.hddcActiveFaultPositionerror.repository.entity.HddcActivefaultpositionerrorEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author zyb
 * @date 2020-11-30
 */
public interface HddcActivefaultpositionerrorRepository extends JpaRepository<HddcActivefaultpositionerrorEntity, String> {
    @Query(nativeQuery = true, value = "select * from hddc_activefault_positionerror where project_name in :projectIds and is_valid='1'")
    List<HddcActivefaultpositionerrorEntity> queryByProjectId(List<String> projectIds);

    @Query(nativeQuery = true, value = "select * from hddc_activefault_positionerror where task_name in :taskIds and is_valid='1'")
    List<HddcActivefaultpositionerrorEntity> queryByTaskId(List<String> taskIds);

    @Query(nativeQuery = true, value = "select * from hddc_activefault_positionerror where create_user = :createID and province = :provinceName and city =:cityName and area =:areaName and is_valid='1'")
    List<HddcActivefaultpositionerrorEntity> queryHddcActivefaultsByCreateuser(String createID, String provinceName, String cityName, String areaName);
    @Modifying
    //@Query(nativeQuery = true, value = "delete from hddc_activefault_positionerror where province = :provinceName and city =:cityName and area =:areaName and extends8 =:savefilename")
    @Query(nativeQuery = true, value = "update hddc_activefault_positionerror set is_valid='0', update_user =:uuser, update_time =:deletedate" +
            " where province = :provinceName and city =:cityName and area =:areaName and extends8 = :savefilename")
    void deleteFileData(String provinceName, String cityName, String areaName, String savefilename, String uuser, Date deletedate);

    @Query(nativeQuery = true, value = "select count(*) from hddc_activefault where  province = :provinceName and city =:cityName and area =:areaName "+
            "and id =:id and name =:afname and is_valid='1'")
    Integer getCountByAreaAndIdAndName(String provinceName,String cityName,String areaName,String id,String afname);

    @Query(nativeQuery = true, value = "select count(*) from hddc_activefault_positionerror where  province = :provinceName and city =:cityName and area =:areaName and is_valid='1'")
    Integer getCountByArea(String provinceName,String cityName,String areaName);

    @Query(nativeQuery = true, value = "select * from hddc_activefault_positionerror where is_valid='1'")
    List<HddcActivefaultpositionerrorEntity> findAll();
}
